package cn.yunhe.entity;

import lombok.Data;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.Serializable;

@Data
/*
例一
 */
@Component(value = "yonghu")
//@Scope(value = "prototype") 默认单例，这个是多例
public class User implements Serializable {
    private String name;
    private int age;

    public User() {
        System.out.println("执行了无参构造");
    }

    //@PostConstruct在注解实例后调用
    @PostConstruct
    public void first(){
        System.out.println( "执行了PostConstruct方法");

    }
// @PreDestroy在bean销毁前调用
    @PreDestroy
    public void last(){
        System.out.println( "执行了PostConstruct方法");

    }


    public String printInfo(){

        return "你好"+name+"今年"+age+"岁";
    }


}
